﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBS.Model;
using IBS.Dal;
using IBS.Model.Base;
using IBS.Bll.Tools;
using IBS.ServiceContracts;
using log4net;

namespace IBS.Bll.KnowledgeBase
{

    public class StreetService : ServiceBase, IStreetService
    {
        #region Fields

        private static readonly ILog log = LogManager.GetLogger(typeof(ServiceBase));

        #endregion

        #region Constructors

        public StreetService(IIbsContext context):base(context)
        {
        }

        #endregion

        #region Members
        
        public IList<Street> GetStreets(Func<Street, bool> predicate, int? page=null)
        {

            var streetsByCriteria = _context.Streets.GetByCriteria(page, predicate);


            return streetsByCriteria;
        }

        public Street GetStreetById(int streetId)
        {
            try
            {
                return _context.Streets.Single(s => s.Id == streetId);
            }
            catch (InvalidOperationException)
            {
                throw new BusinessException("Street does not exist");
            }
        }

        #endregion

    }
}
